package com.cgsd.heyu.ui.Integral;

import android.app.Activity;
import android.content.Intent;

import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.cgsd.heyu.R;
import com.cgsd.heyu.adapter.IntegralShopAdapter;
import com.cgsd.heyu.entity.GoodsEntity;
import com.cgsd.heyu.presenter.BasePresenter;
import com.cgsd.heyu.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiaoxing
 * Description 积分商城
 * CreateData: 2021/1/7
 */
public class IntegralShopActivity extends BaseActivity<BasePresenter> {
    private String[] imgs = {"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1072125732,909409303&fm=26&gp=0.jpg","https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1919306804,862012100&fm=26&gp=0.jpg",
    "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2927217418,3147915576&fm=26&gp=0.jpg"};
    private IntegralShopAdapter adapter;
    private List<GoodsEntity> data = new ArrayList<>();

    public static void actionStart(Activity activity){
        Intent intent = new Intent(activity,IntegralShopActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_integral_shop;
    }

    @Override
    protected void initView() {
        RecyclerView mRecyclerView = findViewById(R.id.mRecyclerView);
        // 创建StaggeredGridLayoutManager实例
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        adapter = new IntegralShopAdapter(this,data);
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        for (int i = 0; i < 20; i++){
            data.add(new GoodsEntity(imgs[i%3]));
        }
        adapter.notifyItemRangeChanged(0,data.size());
    }
}
